Skip to content

fix(transaction-pay-controller): use Infura endpoint for live token balance queries#8839

Merged
matthewwalsh0 merged 12 commits into
mainfrom
fix/pay-infura-balance-nonce
Jun 1, 2026
Merged

fix(transaction-pay-controller): use Infura endpoint for live token balance queries#8839
matthewwalsh0 merged 12 commits into
mainfrom
fix/pay-infura-balance-nonce

Conversation

@matthewwalsh0
Copy link
Copy Markdown
Member

@matthewwalsh0 matthewwalsh0 commented May 18, 2026

Explanation

When querying a live on-chain token balance, the controller previously resolved the network client using findNetworkClientIdByChainId, which returns whatever endpoint is currently selected for that chain — including custom RPC endpoints. Custom RPC endpoints may not support the pending block tag used by these calls, causing the query to fail.

This change adds a preference for the chain's Infura endpoint when one is configured, falling back to the existing findNetworkClientIdByChainId behaviour if no Infura endpoint is configured or if the lookup throws.

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

Note

Medium Risk
Changes which RPC endpoint serves balance checks and on-chain amount reads before Relay submit; wrong endpoint selection could block or mis-validate pay deposits, though Infura preference falls back to the default client.

Overview
Introduces shared provider utilities (getNetworkClientId, rpcRequest) so chain RPC calls go through the controller messenger’s provider.request instead of ethers Web3Provider / Contract.

Live token balances (getLiveTokenBalance) now call eth_getBalance / eth_call with the pending block tag and pass preferInfura: true, picking the chain’s Infura networkClientId when configured and otherwise using findNetworkClientIdByChainId—addressing failures on custom RPCs that don’t support pending queries.

The same RPC helper path is used for fiat source amount resolution and transfer amount from tx hash (receipt logs, debug_traceTransaction, eth_getTransactionByHash). Across, Relay, and gas estimation call sites switch to getNetworkClientId for consistency.

Messenger AllowedActions and test mocks register NetworkController:getNetworkConfigurationByChainId. Changelog documents the Infura preference for live balance queries.

Reviewed by Cursor Bugbot for commit 4ca5364. Bugbot is set up for automated code reviews on this repo. Configure here.

@matthewwalsh0 matthewwalsh0 force-pushed the fix/pay-infura-balance-nonce branch 4 times, most recently from 77eee8b to a9de394 Compare May 18, 2026 14:14
@matthewwalsh0 matthewwalsh0 force-pushed the fix/pay-infura-balance-nonce branch from 4c70b63 to 8350c8e Compare May 27, 2026 23:14
@matthewwalsh0 matthewwalsh0 force-pushed the fix/pay-infura-balance-nonce branch from aa7c99a to 2b7b6e0 Compare May 29, 2026 21:01
@matthewwalsh0 matthewwalsh0 marked this pull request as ready for review May 29, 2026 23:23
@matthewwalsh0 matthewwalsh0 requested review from a team as code owners May 29, 2026 23:23
@matthewwalsh0 matthewwalsh0 force-pushed the fix/pay-infura-balance-nonce branch from 2472294 to 4ca5364 Compare June 1, 2026 09:45
@matthewwalsh0 matthewwalsh0 added this pull request to the merge queue Jun 1, 2026
Merged via the queue into main with commit 7b49e02 Jun 1, 2026
370 checks passed
@matthewwalsh0 matthewwalsh0 deleted the fix/pay-infura-balance-nonce branch June 1, 2026 11:12
pull Bot pushed a commit to dmrazzy/core that referenced this pull request Jun 4, 2026
…MetaMask#8992)

## Explanation

Add flag to exclude networks from using infura for live balance.
It is needed primarily for Monad, related to PR:
MetaMask#8839

## References

<!--
Are there any issues that this pull request is tied to?
Are there other links that reviewers should consult to understand these
changes better?
Are there client or consumer pull requests to adopt any breaking
changes?

For example:

* Fixes #12345
* Related to #67890
-->

## Checklist

- [X] I've updated the test suite for new or updated code as appropriate
- [X] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [X] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md)
- [X] I've introduced [breaking
changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md)
in this PR and have prepared draft pull requests for clients and
consumer packages to resolve them

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Changes which RPC endpoint validates live balances before pay
quotes/submit; misconfigured flags could cause wrong or failed balance
reads on affected chains.
> 
> **Overview**
> Adds remote feature flag
**`confirmations_pay_extended.excludeChainIdsFromInfura`** so specific
chains can opt out of preferring Infura for **live on-chain balance**
RPCs (e.g. Monad).
> 
> Introduces **`isChainExcludedFromInfura`** (case-insensitive chain ID
match) and wires **`getLiveTokenBalance`** to pass **`preferInfura:
false`** when the chain is listed, so balance queries use the default
network client instead of forcing the Infura endpoint. Behavior is
unchanged for chains not in the list.
> 
> Unit tests cover the flag helper and Infura skip/use paths in live
balance fetching; the package changelog documents the change.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
e244127. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants